<?php

use Faker\Factory as Faker;
use App\Models\OrderGoods;
use App\Repositories\OrderGoodsRepository;

trait MakeOrderGoodsTrait
{
    /**
     * Create fake instance of OrderGoods and save it in database
     *
     * @param array $orderGoodsFields
     * @return OrderGoods
     */
    public function makeOrderGoods($orderGoodsFields = [])
    {
        /** @var OrderGoodsRepository $orderGoodsRepo */
        $orderGoodsRepo = App::make(OrderGoodsRepository::class);
        $theme = $this->fakeOrderGoodsData($orderGoodsFields);
        return $orderGoodsRepo->create($theme);
    }

    /**
     * Get fake instance of OrderGoods
     *
     * @param array $orderGoodsFields
     * @return OrderGoods
     */
    public function fakeOrderGoods($orderGoodsFields = [])
    {
        return new OrderGoods($this->fakeOrderGoodsData($orderGoodsFields));
    }

    /**
     * Get fake data of OrderGoods
     *
     * @param array $postFields
     * @return array
     */
    public function fakeOrderGoodsData($orderGoodsFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'order_id' => $fake->randomDigitNotNull,
            'goods_id' => $fake->randomDigitNotNull,
            'number' => $fake->randomDigitNotNull,
            'attribute_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $orderGoodsFields);
    }
}
